/**
 * Copyright (c) 2011-2015 1lifes.com
 * HSJ java-handlersocket
 * Id: OpenIndexPacket.java
 */
package com.elifes.hsj.packet;

import java.util.List;

import com.elifes.hsj.util.CollectionUtil;

/**
 * 描述：
 * @author yangqiang
 * @createtime 2011-11-12下午5:10:09
 *
 */
public class OpenIndexPacket extends AbstractPacket{
	private final String dbName;
	private final String tblName;
	private final String indexName;
	private final List<String> columnNames;
	private final List<String> filterFieldList;
	
	public OpenIndexPacket(String indexId, String db, String tableName, String indexName,
			List<String> columnNames, List<String> filterFieldList) {
		type = PacketEnum.OPEN_INDEX;
		this.indexId = indexId;
		this.dbName = db;
		this.tblName = tableName;
		this.indexName = indexName;
		this.columnNames = columnNames;
		this.filterFieldList = filterFieldList;
	}
	
	@Override
	protected void encodeHeader(StringBuilder reqMsg) {
		reqMsg.append(autoAppendTab(OPERATOR_OPEN_INDEX));
	}
	@Override
	protected void encodeBody(StringBuilder reqMsg) {
		reqMsg.append(autoAppendTab(indexId))
			  .append(autoAppendTab(dbName))
			  .append(autoAppendTab(tblName))
			  .append(autoAppendTab(indexName))
			  .append(CollectionUtil.join(columnNames));
		if(filterFieldList != null && filterFieldList.size() > 0){
			reqMsg.append(TAB_TOKEN).append(CollectionUtil.join(filterFieldList));
		}
	}

	public String getDbName() {
		return dbName;
	}
	


}
